package com.woniuxy.config.rabbitmq;

import com.rabbitmq.client.impl.AMQImpl;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: 马宇航
 * @Description: 主题模式 订单队列
 * @DateTime: 25/10/27/星期一 15:19
 * @Component: 成都蜗牛学苑
 **/
@Configuration //第三方的配置类，都会使用Configuration来配置，比如，RedisTemplate，RabbitTemplate；
public class TopicOrderConfig {
    //声明3个队列
    @Bean
    public Queue orderSuccessQueue(){
        return new Queue("orderSuccess");
    }
    @Bean
    public Queue orderSuccessMsgQueue(){
        return new Queue("orderSuccessMsg");
    }
    @Bean
    public Queue orderPayingQueue(){
        return new Queue("orderPaying");
    }
    //声明 topick交换机: 返回值不要用多态，写成父接口。
    @Bean
    public TopicExchange orderTopicExchange(){
        return new TopicExchange("orderTopicExchange");
    }
    //binding的时候，Exchange会有点麻烦
    @Bean
    public Binding orderSuccessBinding(){
        return BindingBuilder.bind(orderSuccessQueue()).to(orderTopicExchange())
                .with("order.success.*");
    }
    //binding的时候，Exchange会有点麻烦
    @Bean
    public Binding orderSuccessMsgBinding(){
        return BindingBuilder.bind(orderSuccessMsgQueue()).to(orderTopicExchange())
                .with("order.success.*");
    }
    //binding的时候，Exchange会有点麻烦
    @Bean
    public Binding orderPayingBinding(){
        return BindingBuilder.bind(orderPayingQueue()).to(orderTopicExchange())
                .with("order.paying.#");
    }
}
